﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TD.bom;

namespace TD.Application
{
    public partial class HomeForm : FormBase
    {
        /// <summary>
        /// Constructeur
        /// </summary>
        public HomeForm()
        {
            InitializeComponent();

            // Il n'y a pas de partie en pause initialement
            m_resumeGame.IsEnabled = false;

            // ni de partie à sauvegarder
            m_saveGame.IsEnabled = false;
        }

        /// <summary>
        /// Click sur 'New Game'
        /// </summary>
        private void OnNewGame(object sender, RoutedEventArgs e)
        {
            // On demande confirmation s'il y a une partie en cours
            if (TD.bom.Game.Instance.State == TD.bom.GameState.Running)
            {
                if (MessageBox.Show("Current game will be lost. Continue anyway ?",
                    "Confirmation", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
                {
                    return;
                }
            }

            // On a la confirmation, on relance une partie
            MainPage.Instance.GameForm.NewGame();
        }

        /// <summary>
        /// Click sur 'Resume Game'
        /// </summary>
        private void OnResumeGame(object sender, RoutedEventArgs e)
        {
            MainPage.Instance.GameForm.Resume();
        }

        /// <summary>
        /// Click sur 'Save Game'
        /// </summary>
        private void OnSaveGame(object sender, RoutedEventArgs e)
        {
            MainPage.Instance.SaveGameForm.Activate();
        }

        /// <summary>
        /// Click sur 'Load Game'
        /// </summary>
        private void OnLoadGame(object sender, RoutedEventArgs e)
        {
            MainPage.Instance.LoadGameForm.Activate();
        }

        /// <summary>
        /// Click sur 'Settings'
        /// </summary>
        private void OnSettings(object sender, RoutedEventArgs e)
        {
            MainPage.Instance.SettingsForm.Activate();
        }

        /// <summary>
        /// Gestionnaire d'activation de la form
        /// </summary>
        protected override void OnActivated()
        {
            // S'il y a une partie à mettre en cours, ces boutons peuvent être affichés
            if (Game.Instance.State == GameState.Running)
            {
                m_resumeGame.IsEnabled = true;
                m_saveGame.IsEnabled = true;
            }
            else
            {
                m_resumeGame.IsEnabled = false;
                m_saveGame.IsEnabled = false;
            }
        }
    }
}
